/**
 * Created by 丸子 on 2018/7/1.
 */
import Vue from 'vue'
import axios from 'axios'
import '../style/style.scss'
import store from '../store'

import { vueBaberrage, MESSAGE_TYPE } from 'vue-baberrage';
Vue.use(vueBaberrage);


import sessionStore from '../store/session'
import * as context from './context'
import {injectVueContext} from './index'
import '../filter'
import Vant from 'vant';
import 'vant/lib/index.css';
import VueI18n from 'vue-i18n'
import animated from 'animate.css'
import { Dialog, Tooltip } from 'element-ui';

import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
Vue.use(VueAwesomeSwiper)



import AlloyFinger from 'alloyfinger'
import AlloyFingerPlugin from 'alloyfinger/vue/alloy_finger_vue'
Vue.use(AlloyFingerPlugin,{
  AlloyFinger
})

Vue.use(Vant);
Vue.use(VueI18n)
Vue.use(animated)

Vue.use(Dialog)
Vue.use(Tooltip);



export const picUrl = 'https://three-kingdom.oss-cn-shenzhen.aliyuncs.com/'
var i18nNameMap = {
  'zh': '繁体中文',
  'en': 'English',
}
var lang = localStorage.getItem('lang');
if (!lang || !i18nNameMap[lang]) {
  lang = 'zh';
}
const i18nMessages ={
  'zh': require('@/assets/languages/zh.json'),
  'en': require('@/assets/languages/en.json')
}
export const i18n = new VueI18n({
  locale: lang,
  messages:i18nMessages
})
var i18nData = {
  lang: lang,
  nameMap: i18nNameMap,
  messages: i18nMessages
};
Vue.mixin({
  data: function () {
    return {
      i18n: i18nData
    }
  },
  methods: {
    selectLang: function (langKey) {
      this.i18n.lang = langKey;
      this.$i18n.locale = langKey;
      localStorage.setItem('lang', langKey)
    }
  }
})

Vue.prototype.$bus = new Vue()
Vue.config.productionTip = false

window.IS_PROD = process.env.NODE_ENV === 'production'
// 图片服务器路径
window.IMG_HOST = process.env.NODE_ENV === 'production' ? '' : '/';

// 后端服务器 URL
// window.API_HOST = process.env.NODE_ENV === 'production' ? 'https://www.nft-hero.vip' : '/online'
// window.API_HOST = process.env.NODE_ENV === 'production' ? 'http://data.seibanet.cn/' : '/online'
// 正式: 'http://heroapi.juhuixinkj.com/api/threeKingdom/',
// 测试: '//heroapi.juhuixinkj.com/api/testthreeKingdom/',
window.API_HOST = process.env.NODE_ENV === 'production' ? '//heroapi.juhuixinkj.com/api/threeKingdom/' : '/online'

// WEB 根路径 URL
window.WEB_URL = process.env.NODE_ENV === 'production' ? '' : ''

// 后端服务器 API URL
window.API_BASE_URL = window.API_HOST

Vue.prototype.$axios = axios

if (process.env.NODE_ENV !== 'production') {
  axios.defaults.withCredentials = true
}
store.registerModule('session', sessionStore())

// 拦截器
axios.interceptors.request.use(function (config) {
  return config
}, function (error) {
  return Promise.reject(error)
})
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
// axios.defaults.headers.post['Content-Type'] = 'application/json'
axios.defaults.baseURL = window.API_BASE_URL

injectVueContext(context)


